<?php

namespace App\Repositories;
use Cache;
use App\Models\JzOrderDetail;
use App\Repositories\Repository;

class JzOrderDetailRepository extends Repository{

    static $tag = 'testing.category';
    static $tableName = 'jz_order_detail';
    /**删除订单
     * @param $oid
     */
    public function deleteOrders($oid){
       return  JzOrderDetail::where('id','=',$oid)->delete();
    }

    /**存储信息
     * @param $data
     * @return mixed
     */
    public function store($data)
    {
        $res = JzOrderDetail::insertGetId($data);
        return $res;
    }

    /**编辑订单
     * @param $data
     * @param $id
     */
    public function edit($data,$id){
        //清除缓存
        $cacheKey = getCacheKey('testing.cache_key.jzorder.info');
        $this->forget($cacheKey.$id);
       return JzOrderDetail::where('id',$id)->update($data);
    }

    /**根据id获取订单详情
     * @param $id
     * @return mixed
     */
    public function orderInfos($id){
        $cacheKey = getCacheKey('testing.cache_key.jzorder.info');
        $data = $this->remember($cacheKey.$id, function () use ($id) {
            return JzOrderDetail::where('id', $id)->first();
        });
        return $data;

    }

    /**根据appid获取所有订单id
     * @param $appid
     * @return mixed
     */
    public function getIdByAppid($appid){
        return JzOrderDetail::where('appid', $appid)->pluck('id');
    }

    /**批量插入
     * @param $data
     */
    public function batchInsertData($data){
      return  JzOrderDetail::batchInsertData(self::$tableName,$data);
    }


    public function model()
    {
        return app(JzOrderDetail::class);
    }

    public function tag()
    {
        return self::$tag;
    }

    public function cacheTime()
    {
        return config('testing.common_cache_time');
    }
}